package com.java.learning.cha1;

import java.io.File;
import java.io.FilenameFilter;

public class FilenameFilterDemo {
    public static void main(String[] args) {
        File file = new File("D:\\Java\\jdk1.8.0_161");

        if (file.exists() && file.isDirectory()) {
            String[] allFileNames = file.list();
            for (String name : allFileNames) {
                System.out.println(name);
            }
            System.out.println("------------------");
            String[] fileFilerNames = file.list(new FilenameFilter() {
                @Override
                public boolean accept(File dir, String name) {
                    return (name.endsWith(".zip") || name.endsWith(".txt"));
                }
            });
            System.out.println("过滤后的文件列表");
            for (String name : fileFilerNames) {
                System.out.println(name);
            }
        }
    }
}
